$(function(){
    let main = document.querySelector("#main")
    let str = ""
    fetch("http://chst.vip:1234/api/getcoupon")
    .then(body=>body.json())
    .then(res=>{
        console.log(res)
        res.result.forEach(item => {
            console.log(item)
            let regExp = /(\/|http)[^>]+\.(jpg|jpeg|png|gif)/g
            let r = item.couponImg.match(regExp)
            console.log(r)
            str += `
                    <div class="info">
                        <a couponid=${item.couponId} href="#">
                            <img src="${r[0]}" alt="">
                            <p>${item.couponTitle}</p>
                        </a>
                    </div>
                    `
        });
        main.innerHTML=str;

        let ua = document.querySelectorAll("a")
        console.log(ua);
        for(var i=0;i<ua.length;i++){
            ua[i].onclick=function(){
                let id=this.getAttribute('couponid')
                console.log(id)
                location.href='./Couponsdetail.html?couponid='+id
            }
        }
    })
})